import Pages from '../../../pages/pages.vue'
import Charge from '../charge-flow/charge-flow.vue'
import Confirm from '../../../confirm/confirm.vue'
import { getAccount, getDataflowList, updateOrderResult, getInvalidOrder, showMsg, setMenuType } from '../../../../vuex/action'

export default {
  name: 'user-list',
  components: {
    'charge-dataflow': Charge,
    'vue-pages': Pages,
    'vue-confirm': Confirm
  },
  data() {
    return {
      searchType: 1,
      searchKeyword: '',
      showCharge: false,
      showConfirm: false,
      DataflowList: [],
      // account: '',
      item: {},
      pages: {
        start: 0,
        totalPages: 0,
        limit: 20
      },
      phone: '',
      activityId: '',
      status: ''
    }
  },
  vuex: {
    getters: {
      fresh: state => state.dataflowListNeedFresh
    },
    actions: {
      xGetAccount: getAccount,
      xGetDataflowList: getDataflowList,
      xUpdateOrderResult: updateOrderResult,
      XGetInvalidOrder: getInvalidOrder,
      xShowMsg: showMsg,
      xSetMenuType: setMenuType
    }
  },
  ready() {
    this.xSetMenuType('activity')
    // this.xGetAccount()
    //   .then((data) => {
    //     this.account = data.balance
    //   })
    this.getList()
  },
  methods: {
    getList() {
      var param = {
        start: this.pages.start,
        limit: this.pages.limit
      }
      if (this.phone) {
        param.phone = this.phone
      }
      if (this.activityId) {
        param.activityId = this.activityId
      }
      if (this.status) {
        param.status = this.status
      }
      this.xGetDataflowList(param)
        .then((data) => {
          this.DataflowList = data.list
          this.pages.totalPages = Math.ceil(data.totalCount / this.pages.limit)
        })
        .catch((res) => {
          this.xShowMsg({
            type: 'danger',
            content: res.error_msg
          })
        })
    },
    updateOrder(orderNo) {
      this.xUpdateOrderResult({
        orderNo: orderNo
      })
        .then((data) => {
          this.xShowMsg({
            type: 'info',
            content: data.result
          })
        })
        .catch((res) => {
          this.xShowMsg({
            type: 'danger',
            content: res.error_msg
          })
        })
    },
    charge(item) {
      this.item = {}
      this.showCharge = true
    },
    invalidOrder(item) {
      this.XGetInvalidOrder({
        orderNo: item.id
      })
        .then((data) => {
          this.item = item
          this.showConfirm = true
        })
        .catch((res) => {
          this.xShowMsg({
            type: 'danger',
            content: res.error_msg
          })
        })
    },
    reCharge() {
      this.showConfirm = false
      this.showCharge = true
    }
  },
  watch: {
    fresh() {
      if (this.fresh) {
        this.getList({})
      }
    }
  }
}
